/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
 *
 * @author Mladen
 */
public class Controll {

     private model.Addition Add;
     private view.MatrixGUI View;
     private model.Adjunct Adj;
     private model.Determinant Det;
     private model.Multiplication Multi;
     private model.Subtraction Sub;
     private model.Cofactor Cof;
     private model.Inverse Inv;
     private model.SkalarMultiplikation Skal;
     private model.Transpose Trans;
  private int[][] First = View.getFirstMatrix();
  private int[][] Second = View.getSecondMatrix();
  
  public Controll (model.Addition Add, model.Cofactor Cof, model.Inverse Inv, model.SkalarMultiplikation Skal, model.Transpose Trans, view.MatrixGUI View, model.Adjunct Adj, model.Determinant Det, model.Multiplication Multi, model.Subtraction Sub){
  
      this.Add = Add;
      this.View = View;
      this.Adj = Adj;
      this.Det = Det;
      this.Sub = Sub;
      this.Multi = Multi;
      this.Cof = Cof;
      this.Inv = Inv;
      this.Skal = Skal;
      this.Trans = Trans;
      this.View.(new MatrixListener());
  }
  class MatrixListener implements ActionListener {
  public void actionPerformed(ActionEvent e) {
    String Operations = View.getTypeOfOperation();
    switch (Operations) {
        case "Addition": if ((First.length == Second.length) && (First[0].length == Second[0].length)) {
            
           int[][] ResultAdd = Add.addition(First, Second);
            View.setResultatrix(ResultAdd);
        }       
        break;
        case "Adjunction": if ((First.length == First[0].length) && (Det.determinantOfMatrix(First) !=0)) {
            int[][] ResultAdj = Adj.adjunctMatrix(First);
            View.setResultatrix(First);
        }       
        break;
        case "Determinant": if (First.length == First[0].length){
            int ResultDet = Det.determinantOfMatrix(First);
            View.setResultNumber(ResultDet);
        }       
        break;
        case "Multiplication": if (First.length == Second[0].length){
            int[][] ResultMulti = Multi.multiplicationMatrix(First, Second);
            View.setResultatrix(ResultMulti);
        }        
            break;
        case "Substraction": if ((First.length == Second.length)&& (Det.determinantOfMatrix(First) !=0)) {
            int[][] ResultSub = Sub.subtractionMatrix(First, Second);
            View.setResultatrix(ResultSub);
        }       
        break;
        case "Cofactor":
            int[][] ResultCof = Cof.calculateCofactor(First);
            View.setResultatrix(ResultCof);
            break;
        case "Inverse": if (Det.determinantOfMatrix(First) != 0){
            double [][] ResultInv = Inv.calculateInverse(First);
            View.setResultatrix(ResultInv);
        }
        break;
        case "SkalarMultiplikation": 
            int [][] ResultSkal = Skal.calculateSkalarMultiplikation(skalar, First);
            View.setResultatrix(ResultSkal);
            break;
        case "Transpose" : 
            int[][] ResultTrans = Trans.transpose(First);
            View.setResultatrix(ResultTrans);
            break;
        default : System.out.print("Nije prepoznata operacija");
    }
      
  
     }
  }
}
 
    
    
        
    
       
    
    

